home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1294 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  108 lines

  1. Path: colossus.holonet.net!windmill!charlie.brown
  2. Distribution: world
  3. Newsgroups: comp.lang.c
  4. From: charlie.brown@windmill.com (Charlie Brown)
  5. Date: Fri, 12 Jan 1996 11:10:00 -0600
  6. Organization: The Windmill Company BBS - 806-792-6116
  7. Subject: Cheap Temp. Sensor    1/2
  8. Message-ID: <59.26227.5782@windmill.com>
  9.  
  10. /****
  11. Try this!!!
  12. Plug a $2 Radio Shack thermister into the joystick port and
  13. you've got a cheap temperature sensor. I attach these with 
  14. speaker wire to monitor 4 snake cages but you don't need to 
  15. do all that soldering just to play with it. The leads on the 
  16. thermister have the right spacing. Just stick it in one of 
  17. these positions: pins 2-3, 6-7, 10-11, or 13-14. Since it's 
  18. a resistor you don't have to worry about getting it backwards.
  19. -------------------
  20. \ 1 2 3 4 5 6 7 8 /
  21.  \ 9 0 1 2 3 4 5 /
  22.   ---------------
  23. The following code will read the port but you'll have to convert
  24. that to the temperature. As the temperature goes up the number read
  25. from the port will go down. The graph of the temp vs what you get
  26. from the port is *almost* a straight line. I have more code that 
  27. calibrates and graphs the temperature if anybody wants it let me 
  28. know. I hate to clutter up the group with a lot of code nobody wants.
  29.  
  30. Here's the code:
  31. ****/
  32.  
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <math.h>
  37. #include <conio.h>
  38.  
  39. int Joy_Port_Address = 0x201; // game port base address
  40. struct hack_bytes
  41. {
  42.         unsigned char hack_hi;
  43.         unsigned char hack_lo;
  44. };
  45. union hack
  46. {
  47.         struct hack_bytes b;
  48.         unsigned int w;
  49. };
  50. /************************************************************************
  51. *                    JOYSTICK_POSITION                                  *
  52. *************************************************************************/
  53. int Joystick_Position(int  which_one)
  54. {
  55.         int counter;
  56.         unsigned char mask;
  57.         union hack hack1,hack2;
  58.  
  59.         mask = (unsigned char) pow(2.0,(double)which_one);
  60.  
  61.         _asm 
  62.         {
  63.                 MOV CX,2000     
  64.                 MOV DX,Joy_Port_Address 
  65.                 
  66.                 MOV AH,mask             
  67.                 
  68.                 OUT DX,AL            
  69.                 MOV AL, 0x34
  70.                 OUT 0x43,AL
  71.                 MOV AL,0
  72.                 OUT 0x40, AL   
  73.                 OUT 0x40, AL
  74.                 OUT 0x43, AL    
  75.                 IN AL,0x40
  76.                 MOV hack1.b.hack_hi,AL
  77.                 IN AL,0x40
  78.                 MOV hack1.b.hack_lo,AL
  79.         }
  80.                 
  81.         READ:
  82.         _asm 
  83.         {
  84.                 IN AL,DX             
  85.                 TEST AL,AH           
  86.                 LOOPNZ READ          
  87.                 MOV counter,CX
  88.                 IN AL,0x40
  89.                 MOV hack2.b.hack_hi,AL
  90.                 IN AL,0x40
  91.                 MOV hack2.b.hack_lo,AL
  92.                 MOV AL, 0x36 
  93.                 OUT 0x43,AL 
  94.                 MOV AL,0
  95.                 OUT 0x40, AL           
  96.                 OUT 0x40, AL           
  97.         }
  98.         
  99.         
  100.         if(counter == 0)
  101.                 return(0);
  102.  
  103.         if(hack2.w > hack1.w)
  104.  
  105. (Continued to next message)
  106. ---
  107.  * QMPro 1.01 41-4987 * BorgBurger:  We do it our way. Your way is irrelevant.
  108.